package com.hy.mechanicalarm.ui.activity;


import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.hy.mechanicalarm.R;
import com.hy.mechanicalarm.baseapp.BaseActivity;
import com.hy.mechanicalarm.ui.fragment.JWSettingFragment;
import com.hy.mechanicalarm.ui.fragment.QTSettingFragment;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *  2018/8/5 15:20
 *  hanyin
 *  hanyinit@163.com
 */
public class SettingActivity extends BaseActivity implements View.OnClickListener{
    @BindView(R.id.btnJwsz)
    Button btnJwsz;
    @BindView(R.id.btnQtsz)
    Button btnQtsz;
    @BindView(R.id.tvBack)
    TextView tvBack;
    JWSettingFragment jwSettingFragment;
    QTSettingFragment qtSettingFragment;

    @Override
    public void initView() {
        super.initView();
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        showjwFragment();
    }

    private void showjwFragment(){
        //开启事务，fragment的控制是由事务来实现的
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        if(jwSettingFragment == null){
            jwSettingFragment = new JWSettingFragment();
        }
        transaction.replace(R.id.frameLayout, jwSettingFragment);

        //提交事务
        transaction.commit();
    }
    private void showqtFragment(){
        //开启事务，fragment的控制是由事务来实现的
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        if(qtSettingFragment == null){
            qtSettingFragment = new QTSettingFragment();
        }
        transaction.replace(R.id.frameLayout, qtSettingFragment);

        //提交事务
        transaction.commit();
    }
    @Override
    public void initListener() {
        super.initListener();
        tvBack.setOnClickListener(this);
        btnJwsz.setOnClickListener(this);
        btnQtsz.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tvBack:
                finish();
                break;
            case R.id.btnJwsz:
                btnJwsz.setBackgroundResource(R.drawable.btn_jwsz1);
                btnQtsz.setBackgroundResource(R.drawable.btn_qtsz2);
                showjwFragment();
                break;
            case R.id.btnQtsz:
                btnQtsz.setBackgroundResource(R.drawable.btn_qtsz1);
                btnJwsz.setBackgroundResource(R.drawable.btn_jwsz2);
                showqtFragment();
                break;
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
